﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Rbac_APi.Application.Command.DepartmentCommand;

namespace T_Rbac_APi.Controllers
{
    /// <summary>
    /// 部门写入信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        private readonly IMediator mediator;

        public DepartmentController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 部门表添加
        /// </summary>
        /// <param name="departmentAddCommand"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DepartmentAdd(DepartmentAddCommand departmentAddCommand)
        {
            departmentAddCommand.CreateDate = DateTime.Now;
            departmentAddCommand.CreateBy = "小明";
            departmentAddCommand.IsDel=false;
            return await mediator.Send(departmentAddCommand);
        }
        /// <summary>
        /// 删除部门表
        /// </summary>
        /// <param name="departmentDelteCommand"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int>DepartmentDelete([FromQuery]DepartmentDelteCommand departmentDelteCommand)
        {
            return await mediator.Send(departmentDelteCommand);
        }
        /// <summary>
        /// 部门表更新
        /// </summary>
        /// <param name="departmentUpdateCommand"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int>DepartmentUpdate(DepartmentUpdateCommand departmentUpdateCommand)
        {
            return await mediator.Send(departmentUpdateCommand);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="departmentDeleteListCommand"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteListDapartment([FromQuery]DepartmentDeleteListCommand departmentDeleteListCommand)
        {
            return await mediator.Send(departmentDeleteListCommand);
        }
    }
}
